version 1.0

workflow run_ssds_terra_upload {
    meta {
        author: "Julian Lucas"
        email: "juklucas@ucsc.edu"
        description: "Uploads files to AnVIL_HPRC bucket with SSDS"
    }

    parameter_meta {
        file_to_copy: "GS uri of the file that needs uploading to the AnVIL_HPRC bucket. Needs to be in the workspace bucket."
        sample_name:  "HG002 or similar name"
        subm_uuid:    "UUID associated with the submission. Can be a new submission."
        subm_name:    "Name for the submission"
        subm_subdir:  "Subdir to put data in. Cannnot have leading or trailing slashses. Will be put after sample_name and before the file name."


    }

    input {
        String file_to_copy
        String sample_name
        String subm_uuid
        String subm_name
        String subm_subdir
    }


        call ssds_terra_upload {
            input:
                file_to_copy  = file_to_copy,
                sample_name   = sample_name,
                subm_uuid     = subm_uuid,
                subm_name     = subm_name,
                subm_subdir   = subm_subdir
    }

}


task ssds_terra_upload {
    input {
        String file_to_copy
        String sample_name
        String subm_uuid
        String subm_name
        String subm_subdir # no leading or trailing slashes
                           # will go after {sample_name}

        Int memSizeGB   = 8
        Int threadCount = 2
        Int diskSize    = 25        
    }


    command <<<
        set -eux -o pipefail
        
        python << CODE
        
        import os
        from ssds import deployment

        ds = deployment._GSStaging(google_billing_project="human-pangenome-ucsc")   # _GSStaging()
        destintation_bucket = "gs://fc-4310e737-a388-4a10-8c9e-babe06aaf0cf" # _GSStaging()

        ## submission_id is generated by uuid (gives unique ID to each submission)
        submission_id       = f"~{subm_uuid}"

        ## submission_name lends some recognizability to the submission
        submission_name     = f"~{subm_name}"

        file_path = f"~{file_to_copy}"
        file_name = os.path.basename(file_path)

        subm_path = f"~{sample_name}/~{subm_subdir}/{file_name}"

        ds.copy(file_path, submission_id, submission_name, subm_path)

        CODE

    >>>

    runtime {
        memory: memSizeGB + " GB"
        cpu: threadCount
        disks: "local-disk " + diskSize + " SSD"
        docker: "humanpangenomics/ssds@sha256:baeb3fe99e9c07189678984ff4b228ece5d3bf9d5b2d623e31edcfe839c3e4a4"
    }
}
